#include "EstimatingSurfaceNormalsModel.h"

#include "core/AppDirectory.h"

namespace {
const QString UserFilename = "pcl.estimating_surface_normals_model.json";
}

EstimatingSurfaceNormalsModel::EstimatingSurfaceNormalsModel()
    : BasePclModel()
{
    setPclHelpPage("https://pcl.readthedocs.io/projects/tutorials/en/master/normal_estimation.html");
}

EstimatingSurfaceNormalsModel& EstimatingSurfaceNormalsModel::get()
{
    static EstimatingSurfaceNormalsModel instance;
    if (instance.filename().isEmpty()) {
        instance.setFilename(AppDirectory::get().getAppDocFile(UserFilename));
        instance.load();
    }
    return instance;
}

void EstimatingSurfaceNormalsModel::fromJson(const QJsonObject& json, QStringList& errorList)
{
    BasePclModel::fromJson(json, errorList);

    pcdFile_ = json["pcdFile"].toString(pcdFile_);
    radiusSearch_ = json["radiusSearch"].toDouble(radiusSearch_);
    level_ = json["level"].toInt(level_);
    scale_ = json["scale"].toDouble(scale_);
}

QJsonObject EstimatingSurfaceNormalsModel::toJson() const
{
    QJsonObject json = BasePclModel::toJson();

    json.insert("pcdFile", QJsonValue(pcdFile_));
    json.insert("radiusSearch", QJsonValue(radiusSearch_));
    json.insert("level", QJsonValue(level_));
    json.insert("scale", QJsonValue(scale_));

    return json;
}
